/*
 * CgDataSection.c
 *
 *  Created on: 2012/06/11
 *      Author: guanxiaoying
 */
#include "../coredef.h"
#include "../cc/cc.h"
#include "cg.h"

static AST gblDefaulVariSection;
static AST gblDefaulFuncSection;
AST  CG_getVariDataSection( AST astDataSection ){
	if( astDataSection == 0 ){
		if( gblDefaulVariSection == 0 ){
			stDataSectionAccess.alloc(1);
			gblDefaulVariSection = stDataSectionAccess.getMax();
			stDataSectionAccess.name.set( gblDefaulVariSection, ".data" );
		}
		return gblDefaulVariSection;
	}
	return astDataSection;
}
AST  CG_getFuncDataSection( AST astDataSection ){
	if( astDataSection == 0 ){
		if( gblDefaulFuncSection == 0 ){
			stDataSectionAccess.alloc(1);
			gblDefaulFuncSection = stDataSectionAccess.getMax();
			stDataSectionAccess.name.set( gblDefaulFuncSection, ".text" );
		}
		return gblDefaulFuncSection;
	}
	return astDataSection;
}
U4  CG_dataSectionAddNew( AST astDataSection, U4 size ){
	U4 offset;
	offset = stDataSectionAccess.size.get( astDataSection );
	size = size%4?((size>>2)+1)<<2:size;
	stDataSectionAccess.size.set( astDataSection, size + offset );
	return offset;
}
